<?php

namespace App\Http\Controllers;

use App\Models\RoleUser;
use App\Models\Throughtrain;
use App\Models\Role;
use App\Models\ThroughtrainComment;
use Illuminate\Http\Request;
use \DB;
use App\Http\Requests;
use App\Http\Controllers\CommonController;
use Illuminate\Http\Response;
use App\Http\Requests\ZtcRequest;
use Illuminate\View\View;
use App\Models\User;
use App\User as aUser;

class ZtcCommentController extends CommonController
{
    public function getIndex(Request $request)
    {
        $data = $request->input();

        $lists = ThroughtrainComment::with('user', 'ztc')->orderBy('throughtrain_apply_id','desc')
            ->where('throughtrain_id', $data['id'])->paginate(10);


        $actions = aUser::getPermissionAction(1901,1);


        return view('ztccomment/index')->with('lists', $lists)->with('throughtrain_id', $data['id'])
            ->with('actions', $actions);
    }


    public function getEdit(Request $request)
    {
        $data = $request->input();
        $list = ThroughtrainComment::where('id', $data['id'])->first();

        return view('ztccomment/edit')->with('list', $list);
    }


    public function postEdit(Request $request)
    {
        $this->validate($request, ['wonderful' => 'required|in:1,0']);

        $data = $request->input();
        $comment =  ThroughtrainComment::where('id', $data['id'])->first();
        ThroughtrainComment::where('id', $data['id'])->update(['wonderful'=>$data['wonderful']]);

        return AjaxCallbackMessage('编辑成功', true, url('ztccomment/index?id='.$comment->throughtrain_id));
    }


    public function postDelete(Request $request)
    {
        $data = $request->input();

        $comment =  ThroughtrainComment::where('id', $data['cid'])->first();
        ThroughtrainComment::where('id', $data['cid'])->delete();

        return AjaxCallbackMessage('删除成功', true, url('ztccomment/index?id='.$comment->throughtrain_id));
    }
}
